package com.xcc.common.page;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcc.common.BeanMaper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @author frosty
 * @description
 * @date 2019-11-12 12:12:18
 */

public class PageParam extends Page {

    private Logger logger= LoggerFactory.getLogger(PageParam.class);
    private Map<String, Object> requestMap;
    public PageParam(Map<String ,Object> map) {
        if(map==null){
            map=new HashMap<>();
        }
        requestMap = map;
        Object size = map.get("size");
        Object current = map.get("current");
        if (size != null) {
            try {
                this.setSize(Integer.parseInt(size.toString()));
            } catch (Exception e) {
                       logger.error("page  size error-->{}",e.getMessage());
            }

        }
        if (current != null) {
            try {
                this.setCurrent(Integer.parseInt(current.toString()));
            } catch (Exception e) {
                     logger.error("page  current error-->{}",e.getMessage());
            }
        }

    }
    public PageParam(int current, int size){
       this.setSize(size);
       this.setCurrent(current);
    }
   public PageParam(){

   }

   public  <T> T mapToObj(Class<T> clz) {
         try {
           /*移除其中两个*/
             requestMap.remove("size");
             requestMap.remove("current");
              T t = (T) BeanMaper.mapToObj(this.requestMap, clz);
             return  t;
         }catch (Exception e){
            logger.error("mapTo -->{}",e.getMessage());
             return null;

         }


   }





}
